<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class BaseModel extends Model
{
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    protected $guarded = ['id'];

    public $timestamps = false;

    protected $dates = ['create_time', 'update_time'];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $model->setAttribute('create_time', $model->freshTimestamp());
        });

        static::updating(function ($model) {
            $model->setAttribute('update_time', $model->freshTimestamp());
        });

        // 如果你不希望 Laravel 自动维护 created_at 和 updated_at 字段，可以取消以下行的注释
        // static::unsetEventDispatcher();
    }
}
